#include <stdio.h>

void printMax(int *array);

int main(int argc, char *argv[]) {

    int i, count;
    int x[3] = { 0 }; // B, C, J.
    int y[3] = { 0 }; // B, C, J.

    scanf("%d", &count);

    for (i = 0; i < count; i++) {
        getchar();
        char a, b;
        scanf("%c %c", &a, &b);

        if (a == 'B') {
            if (b == 'C') x[0]++;
            if (b == 'J') y[2]++;
        }
        if (a == 'C') {
            if (b == 'B') y[0]++;
            if (b == 'J') x[1]++;
        }
        if (a == 'J') {
            if (b == 'B') x[2]++;
            if (b == 'C') y[1]++;
        }
    }

    int winx = x[0] + x[1] + x[2];
    int winy = y[0] + y[1] + y[2];
    printf("%d %d %d\n", winx, count - winx - winy, winy);
    printf("%d %d %d\n", winy, count - winx - winy, winx);

    printMax(x);
    printf(" ");
    printMax(y);
    printf("\n");

    return 0;
}


void printMax(int *array) {
    if (*array >= *(array + 1) && *array >= *(array + 2))
        printf("%c", 'B');
    else if (*(array + 1) > *array && *(array + 1) >= *(array + 2))
        printf("%c", 'C');
    else
        printf("%c", 'J');
}
